#include "array.h"
#include "sparse.h"
#include "parser.h"
#include "vp.h"
#include <getopt.h>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

int main(int argc, char* argv[]) {
    Array<real> pred;
    const char* modelfile = "vpmodel";
    const char* predfile = "vppred";
    const char* help = "Usage: %s [ -m modelfile ] [ -o outputfile ] testset\n";
    int option;
    while ((option = getopt(argc, argv, "m:o:")) != EOF) {
        switch (option) {
            case 'm':
                modelfile = optarg;
                break;
            case 'o':
                predfile = optarg;
                break;
            case '?':
                fprintf(stderr, help, argv[0]);
                exit(1);
                break;
        }
    }
    if (argv[optind] == 0) {
        fprintf(stderr, help, argv[0]);
        exit(1);
    }
    ofstream ofs(predfile);
    Array<svector*> s;
    parser p(argv[optind]);
    p.parse(s);
    perceptron vp;
    vp.read(modelfile);
    vp.test(s, pred);
    for (int i = 0; i < s.size(); i++) {
        ofs << pred[i] << endl;
        delete s[i];
    }
    return 0;
}
